/**
 *    Copyright 2014 all reserved by Ihome corporate, any persons
 *    or corporate must not use this code for business purpose before
 *    permission is gained.
 *  
 *    ******                                      ******
 *    ******   I Love My Home       ******
 *    ******                                      ******
 *    
 *    Author: DMF
 *    Create Date: Mar 19, 2014
 *
 */
package com.ihome.servlet;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.ihome.common.util.IHConstants;
import com.ihome.common.util.IHLogger;
import com.ihome.dao.BaseDAO;
import com.ihome.orm.entity.IhParamList;

public class IHStartupServlet extends HttpServlet {

	@Resource
	private BaseDAO dao;

	@Override
	public void init(ServletConfig config) throws ServletException {

		List paramList = dao.listAll("IhParamList");
		if (paramList == null)
			IHLogger.logMessage(IHLogger.ERROR, "Config info capture failed");
		else {
			Iterator iterator = paramList.iterator();
			while (iterator.hasNext()) {
				IhParamList param = (IhParamList) iterator.next();

				String keyNm = param.getKeyNm();
				String internalValue = param.getInternalValue();

				if ("ROUND_IAMGE_LOCATION".equals(keyNm))
					IHConstants.ROUND_IMAGE_LOCATION = internalValue;
				if ("FLAT_IAMGE_LOCATION".equals(keyNm))
					IHConstants.FLAT_IAMGE_LOCATION = internalValue;
				if ("LOCAL_IMAGE_LOCATION".equals(keyNm))
					IHConstants.LOCAL_IMAGE_LOCATION = internalValue;
				if ("FACE_PICTURE_LOCATOIN".equals(keyNm))
					IHConstants.FACE_PICTURE_LOCATION = internalValue;
			}
		}
	}
}
